<?php 
////////////////////////////////////////////////////////////////////////////
//                                                                        //
// NOTICE OF COPYRIGHT                                                    //
//    https://freedeansoffice.svn.sourceforge.net/svnroot/freedeansoffice/trunk                                                                    //
// Dean`s Office for Moodle                                               //
// Электронный деканат                                                    //
// <http://deansoffice.ru/>                                               //
//                                                                        //
// Copyright (C) 2008-2999  Alex Djachenko (Алексей Дьяченко)             //
// alex-pub@my-site.ru                                                    //
// Copyright (C) 2008-2999  Evgenij Cigancov (Евгений Цыганцов)           //
//                                                                        //
// This program is free software: you can redistribute it and/or modify   //
// it under the terms of the GNU General Public License as published by   //
// the Free Software Foundation, either version 3 of the Licensen.        //
//                                                                        //
// This program is distributed in the hope that it will be useful,        //
// but WITHOUT ANY WARRANTY; without even the implied warranty of         //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          //
// GNU General Public License for more details.                           //
//                                                                        //
// You should have received a copy of the GNU General Public License      //
// along with this program.  If not, see <http://www.gnu.org/licenses/>.  //
//                                                                        //
////////////////////////////////////////////////////////////////////////////

// Подключаем библиотеки
require_once('lib.php');
require_once('form.php');

//вывод на экран
//печать шапки страницы

// массив с id персон
$personstr = optional_param('personlist', null, PARAM_TEXT);
$personids = explode('_', $personstr);

$departmentid = optional_param('departmentid', 0, PARAM_INT);
$appointmentid = optional_param('appointmentid', 0, PARAM_INT);

// id субдоверенночти
$subid = optional_param('id', 0, PARAM_INT);
// id доверенности
$aclwarrantid = optional_param('aclwarrantid', 0, PARAM_INT);

$DOF->modlib('nvg')->print_header(NVG_MODE_PORTAL);

// проверяем доступ
if ($DOF->im('acl')->is_access('give_warrant'))
{
	$customdata = new stdClass();
	$customdata->dof = $DOF;
	$customdata->personids = $personids;
	$customdata->aclwarrantid = $aclwarrantid;
	$customdata->departmentid = $departmentid;
	$customdata->appointmentid = $appointmentid;
	$customdata->id = $subid;
	    
	// если передан id субдоверенности - получаем данные для ее редактирования
	if ($subid)
	{
	    $data = array();
	    $data['acls'] = $DOF->storage('acl')->get_records(array('aclwarrantid' => $subid));
	    $data['warrant'] = $DOF->storage('aclwarrants')->get_record(array('id' => $subid));
	    $customdata->subwarrant = $data;
 	}
	    
	$givewarrant = new dof_im_give_warrant_acl_form($DOF->url_im('acl', '/givewarrant.php', array()), $customdata, 'post');
	$givewarrant->display();
	
	// если форма отправлена и не отменена - выполняем ее обработку
	if ($givewarrant->is_submitted())
	{
		if ($givewarrant->process() AND confirm_sesskey() AND ! $givewarrant->is_cancelled())
		{
		    echo $DOF->get_string('warrant_regive_success', 'acl');
		}else
		{
		    echo $DOF->get_string('warrant_regive_failed', 'acl');
		}    
	}
}

//печать подвала
$DOF->modlib('nvg')->print_footer(NVG_MODE_PORTAL);

?>